<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" style="margin:6px 0" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item class="qryItem" label="责任人" style="margin-left:-14px">
          <el-input v-model="queryParam.qry_responsible" placeholder="工号或姓名" @keyup.enter.native="doQuery"></el-input>
        </el-form-item>
        <el-form-item class="qryItem" label="任务名称">
          <el-input v-model="queryParam.qry_taskname" placeholder="关键字" @keyup.enter.native="doQuery"></el-input>
        </el-form-item>
        <el-form-item class="qryItem" label="里程碑名称">
          <el-input v-model="queryParam.qry_milepostname" placeholder="关键字" @keyup.enter.native="doQuery"></el-input>
        </el-form-item>
        <el-form-item class="qryItem" label="任务状态">
          <el-select v-model="taskstateList" multiple placeholder="请选择项目状态" style="width:240px">
            <el-option v-for="item in codeModel.taskstateList" :key="item.code" :label="item.name" :value="item.code"> </el-option>
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar class="tl-list-toolbar" ref="toolbar" :refMainTable="$refs.mainTable" currentModuleTableCode="sdProjectTask/main" :startColumn="3" @add="openAddDialog('editForm')" :isDisplayAdd="false" :isDisplayDeleteBatch="false" @exportExcel="doExportExcel" :isDisplayExport="false" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn">
        <!-- <el-button class="filter-item" type="primary" icon="el-icon-plus" @click="openAddDialog('editProjectRef')">按项目添加
        </el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-plus" @click="openAddDialog('editProjectTaskTemplateRef')">按模板添加</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-download" @click="doExportExcel" v-hasPermission="['sys:excel:export']">导出</el-button> -->
      </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" :row-style="tableRowStyle" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column>
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="milepostname" label="所属里程碑" width="300px" sortable="custom" sort-by="milepostname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="generatetaskcode" label="任务编号" width="100px" sortable="custom" sort-by="taskcode" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="taskname" label="任务名称" width="300px" sortable="custom" sort-by="taskname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="taskdetail" label="任务内容" width="150px" sortable="custom" sort-by="taskdetail"
          align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="responsible" label="责任人" width="100px" sortable="custom" sort-by="responsible" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="responsiblecode" label="责任人工号" width="100px" sortable="custom" sort-by="responsiblecode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="disptaskstate" label="任务状态" width="100px" sortable="custom" sort-by="taskstate" align="center" header-align="center" :show-overflow-tooltip="true">
          <template v-slot="scope">
            <el-tag :type="changeStateType(scope.row.taskstate)">
              {{ scope.row.disptaskstate }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="taskschedule" label="任务进度" width="150px" sortable="custom" sort-by="taskschedule" align="center" header-align="center" :show-overflow-tooltip="true" :formatter="percentageFormat"> </el-table-column>
        <el-table-column prop="planstartdate" label="计划开始日期" width="150px" sortable="custom" sort-by="planstartdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="actualstartdate" label="实际开始日期" width="150px" sortable="custom" sort-by="actualstartdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="planenddate" label="计划完成日期" width="150px" sortable="custom" sort-by="planenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="actualenddate" label="实际完成日期" width="150px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="taskdistributedate" label="任务派发日期" width="150px" sortable="custom" sort-by="taskdistributedate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i
                class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)"
                :disabled="scope.row.state !== 0 && scope.row.state !== 2">编辑</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" :disabled="scope.row.state !== 0 && scope.row.state !== 2"
                @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column> -->
        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-button type="text" icon="el-icon-view" @click="openViewDialog('editFeedbackList', scope.row.id)" :disabled="scope.row.taskstate === '0'">
            历史进度
          </el-button>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh" :projectinfo="projectinfo"></tl-edit>
      <tl-project ref="editProjectRef" @refresh="doRefresh" :projectCode="projectinfo.projectcode" :projectinfo="projectinfo" :isSingleSelect="false"> </tl-project>
      <tl-projecttask-template ref="editProjectTaskTemplateRef" @refresh="doRefresh" :projectCode="projectinfo.projectcode" :projectinfo="projectinfo" :isSingleSelect="false"> </tl-projecttask-template>
      <tl-edit-Feedbacklist ref="editFeedbackList" @refresh="doRefresh"></tl-edit-Feedbacklist>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
import tlProject from './editProjectRef'
import tlProjecttaskTemplate from './editProjectTaskTemplateRef'
import tlEditFeedbacklist from '../gpmProjectTaskFeedback/refList'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
import { filterObjectNull, rmbFormat } from '@tapui/utils/util'
export default {
  name: 'sdProjectTask',
  mixins: [mixin_list],
  components: { tlEdit, tlProject, tlProjecttaskTemplate, tlEditFeedbacklist },
  data() {
    return {
      description: '项目任务-列表查询',
      urlPrefix: '/sd/projectTask/',
      url: {
        queryCodeList: '/sd/projectTask/dataCodeList'
      },
      reduceHeight: 298,
      // 排序参数
      sorterInfo: {
        sidx: 'planenddate asc,planstartdate ',
        sord: 'asc'
      },
      taskstateList: []
    }
  },
  props: {
    projectinfo: {},
    projectId: {
      type: [Number, String],
      default: ''
    }
  },
  methods: {
    /** 表格双击事件 */
    doRowDbClick(row, column, event) {
      if (row.taskstate === '0' || row.taskstate === '1') {
        this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
      } else {
      this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
      }
    },
    /** 获取查询参数 */
    getQueryParams() {
      let param = {}
      if (this.taskstateList.length > 0) {
        param.qry_taskstate = this.taskstateList.join(',')
      }
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
      }
      Object.assign(param, this.queryParam, this.sorterInfo, this.filtersInfo)
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      param.qry_projectcode = this.projectinfo.projectcode
      param.qry_state = 9
      return filterObjectNull(param)
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    /** 格式化任务进度 */
    percentageFormat(row, column, cellValue, index) {
      let taskScheduleValue = row[column.property]
      if (typeof taskScheduleValue === 'undefined' || taskScheduleValue === null || taskScheduleValue === '') {
        return '0%'
      }
      taskScheduleValue = taskScheduleValue + '%'
      return taskScheduleValue
    },
    /** 改变任务状态标签颜色 */
    changeStateType(state) {
      return state === '0' ? 'info' : state === '-1' ? 'danger' : state === '2' ? 'success' : ''
    },
    // 行颜色
    tableRowStyle(row, index) {
      // 如果计划完成时间为空，则行颜色为空
      if (row.row.planenddate === undefined || row.row.planenddate === null || row.row.planenddate === '') {
        return {}
      } else {
        let currentTime = new Date()
        // 替换字符 变为标准格式
        let customTime = row.row.planenddate.replace('-', '/')
        customTime = new Date(Date.parse(customTime))
        // 如果当前时间 > 计划达成日期
        if (currentTime > customTime && !row.row.actualenddate) {
          return { 'background-color': '#B8860B', color: '#FFFFFF' }
        }
      }
    }
  }
}
</script>

<style scoped>
.app-container {
  margin: 0;
}
</style>
